package com.java.controller;

import com.java.pojo.CheckReveal;
import com.java.pojo.Course_info;
import com.java.pojo.Teacher_info;
import com.java.service.TeacherFunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * description:描述
 * author:作者
 * time:2020/11/24 21:35
 */
@Controller
public class TeacherFunctionController {

    @Autowired
    private TeacherFunctionService teacherFunctionService;

    /**
     * 通过微信号查看教师个人信息
     * @param teacherWxid
     * @return
     */
    @RequestMapping("/getTeacherInfoByWxid.do")
    public @ResponseBody Teacher_info getTeacherInfoByWxid(String teacherWxid) throws Exception {
        if("".equals(teacherWxid)){
            throw new Exception();
        }
        return teacherFunctionService.findStudentInfoByWxid(teacherWxid);
    }

    /**
     * 修改教师个人信息
     * @param teacherInfo
     * @return
     */
    @RequestMapping("/alertTeacherInfo.do")
    public @ResponseBody boolean setTeacherInfo( @RequestBody Map<String,Object> teacherInfo){
        Teacher_info teacher_info = new Teacher_info();
        teacher_info.setCode((String) teacherInfo.get("code"));
        teacher_info.setTeacherWxid((String) teacherInfo.get("teacherWxid"));
        teacher_info.setTeacherName((String) teacherInfo.get("teacherName"));
        teacher_info.setPassword((String) teacherInfo.get("password"));
        System.out.println(teacher_info.toString());
        return teacherFunctionService.alertTeacherInfo(teacher_info);
    }

    /**
     * 通过微信号查看教师课程信息
     * @param teacherWxid
     * @return
     */
    @RequestMapping("/getTeacherCourseByWxid.do")
    public @ResponseBody List<Course_info> getTeacherCourseByWxid(String teacherWxid) throws Exception {
        if(teacherWxid.equals("")){
            throw new Exception();
        }
        return teacherFunctionService.findTeacherCourseByWxid(teacherWxid);
    }

    /**
     * 添加课程
     * @param course_info
     * @return
     */
    @RequestMapping("/addCourseInfo.do")
    public @ResponseBody boolean addCourseInfo( @RequestBody Map<String,Object> course_info){
        Course_info courseInfo = new Course_info();
        courseInfo.setCourse_name((String) course_info.get("course_name"));
        courseInfo.setTeacher_id((String) course_info.get("teacherWxid"));
        courseInfo.setCourse_sum((String) course_info.get("course_sum"));
        courseInfo.setCourse_now((String) course_info.get("course_now"));
        courseInfo.setComment((String) course_info.get("comment"));
        System.out.println(courseInfo.toString());
        return teacherFunctionService.addCourseInfo(courseInfo);
    }
    /**
     * 修改课程
     * @param course_info
     * @return
     */
    @RequestMapping("/updateCourseInfo.do")
    public @ResponseBody boolean updateCourseInfo( @RequestBody Map<String,Object> course_info){
        Course_info courseInfo = new Course_info();
        courseInfo.setUuid((String) course_info.get("course_id"));
        courseInfo.setCourse_name((String) course_info.get("course_name"));
        courseInfo.setCourse_sum((String) course_info.get("course_sum"));
        courseInfo.setCourse_now((String) course_info.get("course_now"));
        courseInfo.setComment((String) course_info.get("comment"));
        System.out.println(courseInfo.toString());
        return teacherFunctionService.updateCourseInfo(courseInfo);
    }

    /**
     * 删除课程
     * @param courseId
     * @return
     */
    @RequestMapping("/deleteCourseInfo.do")
    public @ResponseBody boolean deleteCourseInfo(String courseId) throws Exception {
        if(courseId.equals("")){
            throw new Exception();
        }
        return teacherFunctionService.deleteCourseInfo(courseId);
    }

    /**
     * 开始签到
     * @param courseId
     * @return
     */
    @RequestMapping("/beginCheck.do")
    public @ResponseBody boolean beginCheck(String courseId,String courseNow) throws Exception {
        if(courseId.equals("")){
            throw new Exception();
        }
        return teacherFunctionService.beginCheck(courseId,courseNow);
    }

    /**
     * 终止签到
     * @param courseId
     * @return
     */
    @RequestMapping("/endCheck.do")
    public @ResponseBody boolean endCheck(String courseId) throws Exception {
        if(courseId.equals("")){
            throw new Exception();
        }
        return teacherFunctionService.endCheck(courseId);
    }


    /**
     * 查看学生签到情况
     * @param checkPara
     * @return
     */
    @RequestMapping("/checkListReveal.do")
    public @ResponseBody List<CheckReveal> checkListReveal(@RequestBody Map<String,Object> checkPara) throws Exception {
        String courseId = (String)checkPara.get("courseId");
        String courseNum = (String)checkPara.get("courseNum");
        if(courseId.equals("") || courseNum.equals("")){
            throw new Exception();
        }
        return teacherFunctionService.checkListReveal(courseId,courseNum);
    }




}
